import MultiDimensionalInt from "./MultiDimensionalInt";
import LevelBaseControl from "../../../LevelCommon/LevelBaseControl";

export default class PasswordBox extends Laya.Script3D {

    /** 是否打开了*/
    public isOpen: boolean = false;
    /** 正确的顺序*/
    public correctIndex: Array<number> = new Array<number>();
    /** 当前所有的密码键*/
    public ChildPassBoxKeyCurIndex: Array<number> = new Array<number>();
    /** 是否用多种情况*/
    public haveMoreCorrect: boolean = false;
    public correctIndexArray: Array<MultiDimensionalInt> = new Array<MultiDimensionalInt>();

    onStart() {
        let length = this.haveMoreCorrect ? this.correctIndexArray.length : this.correctIndex.length;
        for (let index = 0; index < length; index++) {
            this.ChildPassBoxKeyCurIndex.push(0);
        }
    }
    
    public CheckPassWord() {
        if (!this.haveMoreCorrect) {
            let length = this.ChildPassBoxKeyCurIndex.length;
            for (let i = 0; i < length; i++) {
                /** 有密码不对*/
                if (this.ChildPassBoxKeyCurIndex[i] != this.correctIndex[i]) {
                    return;
                }
            }
        }
        else {
            /** 多种情况判断*/
            let length = this.correctIndexArray.length;
            for (let i = 0; i < length; i++) {
                let correctValue: Array<number> = this.correctIndexArray[i].intArray;
                /** 是否有一样的*/
                let isHaveSame: boolean = false;
                for (let index = 0; index < correctValue.length; index++) {
                    let item = correctValue[index];
                    if (item == this.ChildPassBoxKeyCurIndex[i]) {
                        isHaveSame = true;
                        break;
                    }

                }

                /** 如果没有一样的  就直接返回 说密码不对*/
                if (!isHaveSame) {
                    return;
                }
            }
        }
        /** 密码对了*/
        this.isOpen = true;
        let levelControl: LevelBaseControl = window.gameFacade.LevelMng.GetCurLevelControl();
        levelControl.DoInteractObjLogic(this.owner.name + "_UnLock");
        console.log("密码对了！！！");
    }
}